'''
预测良性恶性乳腺癌
1、网上获取数据（工具pandas）
原始数据的下载地址：
https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/
2、数据缺失值处理
3、数据分割
4、标准化
5、LogisticRegression估计器流程
6、获取精确率和召回率
       classification_report

'''

import pandas as pd
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler

columns_names = ['Sample code number', 'Clump Thickness', 'Uniformity of Cell Size', 'Uniformity of Cell Shape',
                 'Marginal Adhesion', 'Single Epithelial Cell Size', 'Bare Nuclei', 'Bland Chromatin',
                 'Normal Nucleoli', 'Mitoses', 'Class']
data = pd.read_csv(
    "https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data",
    names=columns_names
)

# 数据缺失值
data.replace("?", np.nan, inplace=True)
data.dropna(inplace=True)
print(data)

# 数据分割
# 特征值
x = data[columns_names[1:10]]
# 目标值
y = data[columns_names[10]]
# 数据分割
x_train, x_test, y_train, y_test = train_test_split(x, y)

# 标准化
ss = StandardScaler()
x_train = ss.fit_transform(x_train)
x_test = ss.transform(x_test)

# 训练模型
lr = LogisticRegression()
lr.fit(x_train, y_train)

predict = lr.predict(x_test)
print(predict)

# 准确率
score = lr.score(x_test,y_test)
print(score)


# 获取精确率和召回率
resport = classification_report(y_true=y_test, y_pred=predict)
print(resport)